package com.jackson.passjava.study.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jackson.passjava.study.entity.SmsStudyTimeEntity;
import com.jackson.passjava.study.service.SmsStudyTimeService;
import com.jackson.passjava.common.utils.PageUtils;
import com.jackson.passjava.common.utils.R;


/**
 * 学习-用户学习时常表
 *
 * @author Liyuhang
 * @email 50875895@qq.com
 * @date 2021-08-16 21:22:26
 */
@RestController
@RequestMapping("study/smsstudytime")
@Slf4j
public class SmsStudyTimeController {
    @Autowired
    private SmsStudyTimeService smsStudyTimeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = smsStudyTimeService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SmsStudyTimeEntity smsStudyTime = smsStudyTimeService.getById(id);
        return R.ok().put("smsStudyTime", smsStudyTime);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SmsStudyTimeEntity smsStudyTime){
		smsStudyTimeService.save(smsStudyTime);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SmsStudyTimeEntity smsStudyTime){
		smsStudyTimeService.updateById(smsStudyTime);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		smsStudyTimeService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @RequestMapping("/member/list/test")
    public R memberStudyTimeTest() {
        SmsStudyTimeEntity studyTimeEntity = new SmsStudyTimeEntity();
        studyTimeEntity.setTotalTime(100); // 学习时长：100分钟
        studyTimeEntity.setQuesType(1L); // 题目类型：1 （javaBasic）
        return R.ok().put("studyTime", Arrays.asList(studyTimeEntity));
    }
    @RequestMapping("/member/list/test/{id}")
    public R memberStudyTimeTest(@PathVariable("id") Long id) {
        SmsStudyTimeEntity studyTimeEntity = new SmsStudyTimeEntity();
        studyTimeEntity.setTotalTime(200); // 学习时长：100分钟
        studyTimeEntity.setQuesType(1L); // 题目类型：1 （javaBasic）
        studyTimeEntity.setId(id);
        log.info("memberStudyTimeTest  studyTime:{}",JSON.toJSONString(studyTimeEntity));
        return R.ok().put("studytime", Arrays.asList(studyTimeEntity));
    }
}
